﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Data.AID;
using Business.AID;
using Business.AID.Extensions;

namespace Presentation.AID.WebPart.Presentation.AID.VWPConsideracao
{
    public partial class VWPConsideracaoUserControl : UserControl
    {
        #region Propriedades
        
        private int IdGoal
        {
            get
            {
                object obj = Request.QueryString["g"];
                return (obj == null) ? 0 : Convert.ToInt32(obj);
            }
        }
        private string Approver
        {
            get
            {
                object obj = Request.QueryString["a"];
                return (obj == null) ? null : obj.ToString();
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
            }
        }

        #region Eventos

        protected void btnComentario_Click(object sender, EventArgs e)
        {
            string txtConsideracao = txtComentario.Text;

            if (txtConsideracao != "")
            {
                Consideracao consideracao = new Consideracao()
                {
                    IdGoal = IdGoal,
                    Consideration = txtComentario.Text,
                    Approver = this.Approver
                };

                ConsideracaoBO consideracaoBO = new ConsideracaoBO();
                consideracaoBO.CreateConsideration(consideracao);
                txtComentario.Text = string.Empty;

                
                Meta meta = new Meta()
                {
                    Id = IdGoal,
                    ConsideracaoFeita = true
                };
                MetaBO metaBO = new MetaBO();
                metaBO.SetConsideration(meta);
                

                Response.Write("<script type='text/javascript'> window.frameElement.commitPopup() </script>");
                Response.Flush();
                Response.End();
            }
            else
            {
                Alert.Show("Favor. Insira sua consideração.");
            }
        }
        
        #endregion
    }
}
